<script>

var mydialog = art.dialog;
function showImgBox(curElement){
	art.dialog.data('curElement',curElement);
	
	<if condition="!isMobile()">
	
	art.dialog.open('{:U('Img/imagesBox')}', {width: 800, height: 500,lock:true,title:'选择图片', ok:function(){
			var d = this.iframe.contentWindow.document;
			var img_url = $(d).find('#Imgselected').attr('img_url');
			$(curElement).parent().find("input").eq(0).val(img_url);
			$(curElement).val('__PUBLIC__'+img_url);
			$(curElement).focus();
			$(curElement).blur();
			curElement.src = '__PUBLIC__'+img_url;
	},close:function(){
		<if condition="isMobile()"> 
			
			if($(".auii_statei_focus").length > 1){
				$(".auii_statei_focus.index"+($(".aui_state_focus").attr("index")*1 - 1)).show().addClass("aui_state_focus");
			}else{
				$("html,body").animate({scrollTop:$.cookie("scroll_hidden")},100);
				$(".modal-shiftfix").removeClass("hidden");
				$("body").removeClass("padding0");
			}
			
			<else/>
			
			if($(".aui_state_lock").length > 0){
			    $(".aui_state_lock").addClass("aui_state_focus");
			}else{
				$("html,body").animate({scrollTop:$.cookie('scroll_hidden')},100);
				$('.modal-shiftfix').removeClass('hidden');
				$('body').removeClass('padding0');
			}
			</if>
		}});
	<else/>
	mydialog.open("{:U('Img/imagesBox')}", {
		width:$(window).width(), id:'imagesBox', height: 300,lock:true,title:'上传图片',yesClose:false, ok:function(){
		var d = this.iframe.contentWindow.document;
		
		
		if($(d).find('#Imgselected').length > 0){
			var img_url = $(d).find('#Imgselected').attr('img_url');
			$(curElement).parent().find("input").eq(0).val(img_url);
			$(curElement).val('__PUBLIC__'+img_url);
			$(curElement).focus();
			$(curElement).blur();
			curElement.src = '__PUBLIC__'+img_url;
			mydialog.list['imagesBox'].close();
			return false;
		}
		
		
		$.post(
		"{:U('Img/Jcrop')}",
		{	type:$(d).find('#type').val(),
			x:$(d).find('#x').val(),
		    y:$(d).find('#y').val(),
			w:$(d).find('#w').val(),
			h:$(d).find('#h').val(),
			src:$(d).find('#img_src').val()
			},
			function(data){
			if(data == 'OK'){
				
				var img_url = $(d).find('#img_src').val().replace('__PUBLIC__', '');
				$(curElement).parent().find("input").eq(0).val(img_url);
				$(curElement).val(img_url);
				$(curElement).focus();
				$(curElement).blur();
				curElement.src = '__PUBLIC__'+img_url;
				
				mydialog.list['imagesBox'].close();
			}
		}
		); 
	}});
	</if>
}


			 
//链接选择框
function showLinkBox(curElement){
	art.dialog.data('curElement',curElement);
	art.dialog.open('{:U('Index/showLink')}', {width: 800, height: 500,lock:true,title:'选择链接'});
}
//链接选择框
function showIconBox(curElement){
	art.dialog.data('curElement',curElement);
	art.dialog.open('{:U('Index/showIcon')}', {width: 800, height: 500,lock:true,title:'选择图标'});
}

  

</script>


<!--头部结束-->


<form class="checkoutform form-horizontal" action="{:U('saveText')}" method="post">
<input type="hidden" name="id" id="id" value="{$info.id}" >
<input type="hidden" name="name" value="{$name}" id="name">

  <div class="form-group">
    <div class="col-sm-12">
    
    <eq name="datatype" value="text">
    <script id="editor" class="ueditorelement" name="content" type="text/plain" style="height:400px; width:100%;" >内容加载中……</script>
	<script>UE.getEditor("editor",{serverUrl:"<?php echo U('Ueditor/upload');?>",autoHeightEnabled:false,elementPathEnabled:false,wordCount:false,toolbars: [[
            'fullscreen', 'source', '|', 'undo', 'redo', '|',
            'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'blockquote', '|', 'forecolor', 'backcolor', 
             'lineheight', '|',
            'customstyle', 'paragraph', 'fontfamily', 'fontsize'
        ]]});</script>
    
     
      
    </eq>
    
    
    
      
      <eq name="datatype" value="image">
    
      <img style="margin:0 auto; margin-top:10px; display:block; max-height:90px; vertical-align:top; max-width:100%;" onclick="showImgBox(this);" src="" id="img_url" />
      
      
     <p style="text-align:center;">点击图片可以更改</p>
      
    </eq>
      
    </div>
  </div>
  
  
  
  
  
  
  <eq name="datatype" value="image">
  <div class="form-group">
    <div class="col-sm-12">
    
    链接：
      <textarea class="form-control" style="height:50px; margin-top:10px;" name="link" id="link" type="text"><?php echo $diydata[$name.'_link'];?></textarea>
      
      
      <a class="btn btn-success btn-sm" style="width:100%; margin-top:5px;" onClick="showLinkBox(this);" href="javascript:void(0);">点击选择链接</a>
      
      
    </div>
  </div>
  </eq>
  
  
  
  
  
  
  
  
</form>


<div id="editcode" style="display:none;">
{$info.content}
</div>


<script>
$('#editcode .main-code').addClass('main-code-replace');
$('#editcode .main-code').removeClass('main-code');

<?php if($_GET['datatype'] == 'text'){?>

var ueditor = UE.getEditor('editor');
function getContent(){
	
    $('#editcode .wrap-box').eq(<?php echo $_GET['index'];?>).html(UE.getEditor('editor').getContent());
	
}


ueditor.addListener("ready", function () {
        // editor准备好之后才可以使用
        ueditor.setContent($('#editcode .wrap-box').eq(<?php echo $_GET['index'];?>).html());

});

<?php }  ?>


$('#img_url').attr('src',$('#editcode .wrap-box').eq({$Think.get.index}).find('img').attr('src'));

   $('#link').val($('#editcode .wrap-box').eq({$Think.get.index}).find('a').attr('href'));
   
</script>

